<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of XMLGen
 *
 * @author Tomek
 */
class XMLGen
{

//put your code here
	private $employees = array();
	private $jobs = array();
	private $dates = array();
	private $locations = array();
	private $jobsOffer = array();
	private $href = array();
	private $XMLName = '';

	public function __construct($XMLName, $employees, $jobs, $dates, $locations, $jobsOffer, $href)
	{
		if (is_array($employees))
			$this->employees = $employees;
		if (is_array($jobs))
			$this->jobs = $jobs;
		if (is_array($dates))
			$this->dates = $dates;
		if (is_array($locations))
			$this->locations = $locations;
		if (is_array($jobsOffer))
			$this->jobsOffer = $jobsOffer;
		if (is_array($href))
			$this->href = $href;
		$this->XMLName = $XMLName;
	}

	public function getEmployees()
	{
		echo '<pre>';
		var_dump($this->employees);
		echo '</pre>';
	}

	public function getJobs()
	{
		echo '<pre>';
		var_dump($this->jobs);
		echo '</pre>';
	}

	public function getDates()
	{
		echo '<pre>';
		var_dump($this->dates);
		echo '</pre>';
	}

	public function getLoc()
	{
		echo '<pre>';
		var_dump($this->locations);
		echo '</pre>';
	}

	public function getJobsOffer()
	{
		echo '<pre>';
		var_dump($this->jobsOffer);
		echo '</pre>';
	}

	public function getHref()
	{
		echo '<pre>';
		var_dump($this->href);
		echo '</pre>';
	}

	public function getName()
	{
		var_dump($this->XMLName);
	}

	public function generateXML()
	{
		$XMLDocument = new DOMDocument('1.0', 'utf-8');
		$XMLDocument->formatOutput = true;

		$Oferty = $XMLDocument->appendChild($XMLDocument->createElement('Oferty'));

		$licznik = count($this->jobs);
		for ($i = 0; $i < $licznik; ++$i) {

			$Oferta = $Oferty->appendChild($XMLDocument->createElement('Oferta'));
			$Oferta->setAttribute('NumerOferty', $i);
			$Oferta->appendChild($XMLDocument->createElement('Praca', trim($this->jobs[$i])));
			$Oferta->appendChild($XMLDocument->createElement('Pracodawca', trim($this->employees[$i])));
			$Oferta->appendChild($XMLDocument->createElement('Lokalizacja', trim($this->locations[$i])));
			$Oferta->appendChild($XMLDocument->createElement('Data', trim($this->dates[$i])));
			$Oferta->appendChild($XMLDocument->createElement('Link', trim($this->href[$i])));
			$Oferta->appendChild($XMLDocument->createElement('Content', trim($this->jobsOffer[$i])));
		}
		file_put_contents($this->XMLName, $XMLDocument->saveXML());
	}

}

?>
